package com.levi.StrategyPattern;

import com.levi.StrategyPattern.Strategy.CashNormal;
import com.levi.StrategyPattern.Strategy.CashRebate;
import com.levi.StrategyPattern.Strategy.CashReturn;

/**
 * @author Levi
 * @description :  将策略模式与简单工厂模式结合起来
 * @since 2022/8/31 15:54
 */

public class CashContextFactory {
    private CashSuper cashSuper = null;

    //    选择策略
    public CashContextFactory(String strategy) {
        switch (strategy) {
            case "正常收费":
                cashSuper = new CashNormal();
                break;
            case "满300返100":
                cashSuper = new CashReturn("300", "100");
                break;
            case "打8折":
                cashSuper = new CashRebate("0.8");
                break;
        }
    }

    //    获取结果
    public double getResult(double money) {
        return cashSuper.acceptCash(money);
    }
}
